﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data.SqlClient;
using System.Data;
using System.Windows.Forms;

namespace deneme
{
    class ClassFillComboBox2
    {
        SqlConnection con = new SqlConnection(ClassSqlConnection.ConnectionString);


        public void comboboxdoldurucu(ComboBox combo, string tabloadi, int kolonnumarasi) //combobox'ı doldurmak için method
        {
            con.Open();
            
            string sql = "SELECT * FROM " + tabloadi + " ORDER BY SehirAd";
            SqlCommand cmd = new SqlCommand(sql, con);
            SqlDataAdapter da = new SqlDataAdapter(cmd);
            DataSet ds = new DataSet();
            ds.Clear();

            da.Fill(ds);

            DataTable table = ds.Tables[0];

            for (int i = 0; i < table.Rows.Count; i++)
            {
                combo.Items.Add(table.Rows[i][kolonnumarasi].ToString());
            }

            con.Close();
        }
    }
}
